package com.xbongbong.paas.enums.bi;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;
import lombok.ToString;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author zcp
 * @version v1.0
 * @since v1.0
 */
@Getter
@ToString
public enum DataSetPermissionEnum {
    /**
     * 编辑者权限
     */
    EDITABLE_RULE(1, "editableRule", "enum.dataSetPermission.name.editable_rule"),
    /**
     * 查看者权限
     */
    VISIBLE_SCOPE_RULE(2, "visibleScopeRule", "enum.dataSetPermission.name.visible_scope_rule"),
    ;
    private int code;
    private String alias;
    private String value;

    DataSetPermissionEnum(int code, String alias, String value) {
        this.code = code;
        this.alias = alias;
        this.value = value;
    }

    /**
     * 根据alias获取枚举
     * @param alias
     * @return
     */
    public static DataSetPermissionEnum getByAlias(String alias){
        return Arrays.stream(values()).filter(cache -> Objects.equals(cache.getAlias(), alias)).findAny().orElse(null);
    }

    public String getValue() {
        return I18nMessageUtil.getMessage(value);
    }
}
